<template>
    <div>
      <van-form @submit="onSubmit">
        <van-field
          v-model="product.productName"
          name="productName"
          label="商品名称"
          placeholder="商品名称"
          :rules="[{ required: true, message: '请填写商品名称' }]"
        />
        <van-field
          v-model="product.price"
          type="text"
          name="price"
          label="价格"
          placeholder="价格"
          :rules="[{ required: true, message: '请填写价格' }]"
        />
        <van-field
          readonly
          clickable
          name="createTime"
          :value="value"
          label="日历"
          placeholder="点击选择日期"
          @click="showCalendar = true"
        />
        <van-calendar v-model="showCalendar" @confirm="onConfirm" />
        <div style="margin: 16px;">
          <van-button round block type="info" native-type="submit">提交</van-button>
        </div>
      </van-form>
    </div>
</template>

<script>
   import  axios from  'axios';
    export default {
        name: "",
      data(){
          return{
            product:{},
            value: '',
            showCalendar: false,
          }
      },
      methods: {
        onConfirm(date) {
          alert(123)
          this.value =  `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`;
          this.showCalendar = false;
        },
        onSubmit(values) {
         axios.post("http://localhost:8080/product/updateOrSave",values).then(res=>{
           this.$router.push("/")
         })
        },
      },
    }
</script>

<style scoped>

</style>
